package csel.controller.listeners;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import csel.controller.decoders.EventDecoder;

/**   
 * Reasons for Existence: define the type of an ActionListener</br>
 * Team Members Responsible</br>
 * Implementation: Tait</br>
 * Testing: Tait</br> 
 * 
 * @author Nikolas Wolfe
 */
public abstract class AbstractActionListener implements ActionListener
{
	protected ActionEvent actionEvent;
	protected EventDecoder eventDecoder;
	private Thread worker;
	
	// required by the EventListener interface
	public abstract void actionPerformed(ActionEvent e);

	// This starts the thread that receives actions
	public void startWorker()
	{
		worker = new Thread(eventDecoder);
		worker.start();
	}
	
	// this kills the thread so there won't be any leakage
	public void killWorker()
	{
		worker.interrupt();
		System.out.println("[CONTROLLER] Worker thread terminated! ");
	}
	
	// this allows the decoder to get the event
	public ActionEvent getActionEvent()
	{
		return this.actionEvent;
	}

	// simple toString
	public String toString()
	{
		return this.getClass().getSimpleName();
	}

	public abstract EventDecoder getEventDecoder();
}
